package com.tool_stdy.thread;

/**
 * Created by yan_li on 2016/1/10.
 */
public class ThreadSync implements Runnable{
    static ThreadSync sync = new ThreadSync();
    static  Integer j=0;

    public  void inscane(){
        for(int i=0;i<10000000;i++){
            synchronized (ThreadSync.class){
                j++;
            }
        }
    }

    @Override
    public void run() {
        inscane();
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(sync);
        Thread t2 = new Thread(sync);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(j);
    }
}
